#include "../glue/sim.h"
#include "iris_net.h"
#include "network.h"

extern Simulator Sim;
using namespace manifold::kernel;

Iris_net::~Iris_net() {
}

Iris_net::Iris_net(int num_nodes)
    : Network(num_nodes, 1, 0)
{
    ii_nodes_cid = new CompId_t[num_nodes];
    ii_pointer = new Iris_interface*[num_nodes];

    for (int i = 0; i < num_nodes; i++)
    {
        ii_nodes_cid[i] = Component::Create<Iris_interface, Network *, ModuleID> (0, this, (ModuleID){i, NI_M});
        ii_pointer[i] = (Iris_interface *) Component::GetComponent(ii_nodes_cid[i]);
        Clock::Register<Iris_interface> ((Iris_interface*)ii_pointer[i], &Iris_interface::tick, &Iris_interface::tock);
    }
}

Network_interface *Iris_net::get_interface (int id)
{
    return (Network_interface *) ii_pointer[id];
}

CompId_t Iris_net::get_cid (int node_id)
{
    return ii_nodes_cid[node_id];
}

void Iris_net::tick()
{
    for (int i = 0; i < num_connections; i++)
    {
        ii_pointer[i]->tick();
    }
}

void Iris_net::tock ()
{
    for (int i = 0; i < num_connections; i++)
    {
        ii_pointer[i]->tock();
    }
}
